package test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.junit.Assert;
import org.junit.Test;

import database.connector.DBConnector;
import database.connector.DatabaseFactory;
import database.live.MySqlDAO;

public class DatabaseTesting {
	
	@Test
	public void testOne() 
	{
		DBConnector dbConnector = DatabaseFactory.getConnector();
		Connection connection = dbConnector.getConnection();
		Assert.assertNotNull(connection);
		dbConnector.closeConnetion();
	}
	
	@Test
	public void testTwo() throws SQLException
	{
		MySqlDAO d = (MySqlDAO) DatabaseFactory.getDAO();
		ResultSet selectQuery = d.selectQuery("SELECT * FROM TEST.TESTTABLE");
		while(selectQuery.next())
		{
			System.out.println(selectQuery.getString(1) +" "+ selectQuery.getString(2)+" "+ selectQuery.getString(3)+" "+ selectQuery.getString(4));
		}
		
		d.closeConnection();
	}
	
	@Test
	public void testThree() throws SQLException
	{
		MySqlDAO d = (MySqlDAO) DatabaseFactory.getDAO();
		if (d.isOpen())
		{
			int count = d.getCount(SQLQuerys.COUNT_ROWS);
			System.out.println("RowCount : " + count);
			System.out.println("Doing insert");
			count = d.insert(SQLQuerys.INSERT_ROW);
			System.out.println("Inserted : " + count);
			count = d.getCount(SQLQuerys.COUNT_ROWS);
			System.out.println("RowCount : " + count);
			System.out.println("Doing delete");
			count = d.delete(SQLQuerys.DELETE_ROW);
			count = d.getCount(SQLQuerys.COUNT_ROWS);
			System.out.println("RowCount : " + count);
			d.closeConnection();
		}
	}


}
